package entity_beans;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

/**
 * Klasa predstavlja Air_Transport korisnika.
 * 
 * @author Uros Krkic
 */
@Entity
@TableGenerator(name = "user_id_generator",
				table = "user_primary_keys",
				pkColumnName="key_pk",
				valueColumnName="value_pk",
				pkColumnValue="user")
@Table(name = "users")
@NamedQueries(
	{
		@NamedQuery(name = "all_users", query = "select u from User u"),
		@NamedQuery(name = "user_by_username", query = "select u from User u where u.username like :username")
	}
)
public class User implements Serializable {

	
	private static final long serialVersionUID = 3597953771847055837L;


	@Id
	@GeneratedValue(strategy = GenerationType.TABLE, generator = "user_id_generator")
	@Column(name = "id")
	private Integer id;
	
	
	/**
	 * Korisnicko ime
	 */
	private String username;
	
	
	/**
	 * Lozinka
	 */
	private String password;
	
	
	/**
	 * Flag da li je korisnik logovan
	 */
	transient private boolean logged = false;
	transient private boolean accessed = false;
	
	
	/**
	 * Default konstruktor
	 */
	public User() {}
	
	
	/**
	 * Konstruktor.
	 * @param username - korisnicko ime
	 * @param password - lozinka
	 */
	public User(String username, String password) {
		this.username = username;
		this.password = password;
	}
	
	
	
	public Integer getId() {
		return id;
	}
	
	public void setId(Integer id) {
		this.id = id;
	}
	
	public String getUsername() {
		return username;
	}
	
	public void setUsername(String username) {
		this.username = username;
	}
	
	public String getPassword() {
		return password;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	
	
	public boolean isLoggedIn() {
		return logged;
	}
	
	public void setLogStatus(boolean flag) {
		this.logged = flag;
	}
	
	
	
	@Override
	public String toString() {
		return username;
	}
	
	
	public void login() {
		this.logged = true;
	}
	
	public void logoff() {
		this.logged = false;
	}

	public boolean isAccessed() {
		return this.accessed;
	}
	
	public void setAccessed(boolean flag) {
		this.accessed = flag;
	}
	
}
